home *** CD-ROM | disk | FTP | other *** search
- Path: teer1.acpub.duke.edu!jyo
- From: John Young Oh <jyo@acpub.duke.edu>
- Newsgroups: comp.lang.c
- Subject: Ability to locate spaces?
- Date: Thu, 15 Feb 1996 22:30:23 -0500
- Organization: Duke University, Durham, NC, USA
- Message-ID: <Pine.SOL.3.91.960215222301.15979A-100000@teer1.acpub.duke.edu>
- NNTP-Posting-Host: teer1.acpub.duke.edu
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
-
- I am trying to write a program that reads an input file and locates where
- the spaces are located. For example, if a line from the input file read:
- 555555.55 5555.55 5555.55
-
- I would like the program to be able to recognize that there are spaces
- between the numbers and keep track of them. What I did was to use
- fgets and read in the line into a string. I then used a for loop
- and checked each array element of the character string and used an
- if statement to see if an array element was a space.
- Here are the lines of code:
-
- FILE *input;
- char *string, buf[200];
- int i, count;
- input = fopen ("data", "r");
- (etc etc etc)
- string = fgets (buf, 199, input);
- for (i = 0; i < 40; ++i)
- {
- if (buf[i] == ' ')
- {
- ++count;
- }
- }
-
- What is wrong with this code? It does not seem to work.
-
- -John Oh
-